package org.sucri.floxs.ext.widget;

import org.sucri.floxs.ext.JsComponent;
import net.sf.json.JSONObject;
import net.sf.json.JSONArray;

import java.util.Map;
import java.util.HashMap;

/**
 * Created by IntelliJ IDEA.
 * User: Wen Yu
 * Date: Jul 10, 2007
 * Time: 10:05:19 PM
 * To change this template use File | Settings | File Templates.
 */
abstract public class ExtWidget implements JsComponent
{
  private static boolean mDebug = true;
  
  private   String     mVarName;
  protected Map<String, Object> mConfig  = new HashMap<String, Object>();

  public ExtWidget()           { }
  public ExtWidget(String var) { setVarName(var); }

  public String getVarName()         { return mVarName; }
  public void   setVarName(String s) { mVarName = s; }

  abstract public    String construct();

  public String render(String var) { setVarName(var); return render(); }
  public String render()           { return "var " + getVarName() + " = " + construct(); }

  public String toString() { return construct(); }

  public static String br() { return mDebug ? "\n" : ""; }
  public static String str(JSONObject s) { return mDebug ? s.toString(2,0) : s.toString(); }
  public static String str(JSONArray  s) { return mDebug ? s.toString(2,0) : s.toString(); }
}
